package com.spark.email.controller;

import com.spark.email.emailservice.service.MailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author sc
 * @DATE 2024/5/21 15:18
 * @Description:
 * @Version 1.0
 */
@RequestMapping("/email")
@RestController
@Slf4j
public class SendEmailController {

    @Autowired
    private MailService mailService;

    /**
     * 发送文本邮件
     * @param to 接收者
     * @param subject 主题
     * @param text 内容
     */
    @GetMapping("/sendTextMail")
    public void sendTextMail(String to,String subject,String text){
        mailService.sendTextMailMessage(to,subject,text);
    }

    /**
     * 发送HTML邮件
     * @param to
     * @param subject
     * @param content
     */
    @GetMapping("/sendHtmlMailMessage")
    public void sendHtmlMailMessage(String to,String subject,String content){
        mailService.sendHtmlMailMessage(to,subject,content);
    }

    /**
     * 发送带附件的邮件
     * @param to
     * @param subject
     * @param content
     */
    @GetMapping("/sendAttachmentMailMessage")
    public void sendAttachmentMailMessage(String to,String subject,String content,String filePath){
        String location = System.getProperty("user.dir");
        log.info("路径：{}",location);
        String png = "E:\\centos\\spring-demo\\spring-email\\src\\main\\resources\\eva.png";
        mailService.sendAttachmentMailMessage(to,subject,content,png);
    }
}
